package com.ruoyi.web.pojo.request.warning;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.utils.CommonUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.domain.warning.WarningFactorRecord;
import com.ruoyi.web.utils.BasePageQuery;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
public class WarningFactorRecordRequest extends BasePageQuery {

    @ApiModelProperty("因子key 全部不传")
    private String factorKey;

    @ApiModelProperty("因子类型 全部不传")
    private String factorType;

    @ApiModelProperty("预警等级 1 一级 2 二级 3 三级")
    private String warningLevel;

    @ApiModelProperty("开始时间")
    private String startTime;

    @ApiModelProperty("开始时间")
    private String endTime;

    @ApiModelProperty("用户id")
    private Long userId;

    @ApiModelProperty("设备id")
    private String deviceId;
    /**
     * @desc  构建查询条件
     * @author fwx 2024/2/1 14:25
     **/
    public void bulidWrapper(QueryWrapper<WarningFactorRecord> query){
        //时间范围
        if(StringUtils.isNotBlank(this.getStartTime()) && StringUtils.isNotBlank(this.getEndTime())){
            query.lambda().between(WarningFactorRecord::getCrtTime,startTime,CommonUtils.computeTime(endTime,1));
        }

        //因子key
        if(StringUtils.isNotBlank(this.getFactorKey())){
            query.lambda().eq(WarningFactorRecord::getFactorKey,this.getFactorKey());
        }

        //预警等级
        if(StringUtils.isNotBlank(this.getWarningLevel())){
            query.lambda().eq(WarningFactorRecord::getWarningLevel,this.getWarningLevel());
        }

        //因子类型
        if(StringUtils.isNotBlank(this.getFactorType())){
            query.lambda().eq(WarningFactorRecord::getFactorType,this.getFactorType());
        }

        //设备ID
        if(StringUtils.isNotBlank(this.getDeviceId())){
            query.lambda().eq(WarningFactorRecord::getDeviceId,this.getDeviceId());
        }

        query.lambda().orderByDesc(WarningFactorRecord::getCrtTime);

    }
}
